package shoooter.entity.nonimage;

import shoooter.geometry.Vec2;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import javax.swing.ImageIcon;
import shoooter.GameState;

public class SimplePlayer extends Player {

    //int rad;
    static int start_rad = 25;
    static int start_hp = 100;
    

    public SimplePlayer(Vec2 vPos, Vec2 vSpe, Vec2 vAcc) {
        super(start_hp);
        this.setvPos(vPos);
        this.setvSpe(vSpe);
        this.setvAcc(vAcc);
        this.rad = start_rad;
    }

    // Load image of ship
    Image spaceShip = new ImageIcon(getClass().getResource("player.png")).getImage();
    
    public void draw(Graphics2D g2d,double mouseX,double mouseY) {

        g2d.setColor(Color.black);
        
       
       // Image image =  Image.createImage("Icon/player.png");
        
        
        //g2d.fillOval((int) this.getX() - this.rad, (int) this.getY() - this.rad, this.rad*2, this.rad*2);
        this.rad = (start_rad*this.hp)/start_hp;
        
        if(this.rad <=3)
            this.rad = 3;

        //draw player
        //g2d.fillOval((int) (this.getX() - this.rad), (int) (this.getY() - this.rad), (int) this.rad*2, (int) this.rad*2);
        //rotate spaceship with mouse coordinates
        //double xx = mouseX + this.getX();
        //double yy = mouseY + this.getY();
        //double ipotenusa = Math.sqrt(Math.pow(xx, 2)+Math.pow(yy, 2));
        
        //double alfa = Math.asin((xx/ipotenusa));
        double alfa = Math.atan2(mouseY - this.getY(), mouseX - this.getX());
        //System.out.println("xx:" + xx + "yy:"+yy);
        //System.out.println("alfa:"+ alfa);
        //arcsin(x/ipo)
        //g2d.rotate(((400.0+mouseX)/(454.0/2.0)+mouseY)%360,this.getX(),this.getY());
        g2d.rotate(-Math.PI/2 +alfa ,this.getX(),this.getY());
        
        //System.out.println("x:"+mouseX + " y:"+mouseY);
        //g2d.drawRect((int) (this.getX() - this.rad), (int) (this.getY() - this.rad), (int) this.rad*2, (int) this.rad*2);
        
        
        // draw the spacenaveship
        g2d.drawImage(spaceShip, (int) (this.getX()) - (int) (spaceShip.getWidth(null)/4), (int) (this.getY()) - (int) (spaceShip.getHeight(null)/4),(int) this.rad*2, (int) this.rad*2,null);
        
        
         
    //    System.out.println(x);
    }

    public void regenerate() {
        if(hp < max_hp)
            hp++;
    }

    public void regenFromState(GameState g) {
        
        regenerate(g.regen_rate);
    }

    public void regenerate(int value) {
        if((hp + value) < max_hp )
            hp += value;
        else
            hp = max_hp;
    }

}